package com.laguille.games.monopoly.server;

import com.laguille.games.monopoly.commons.event.Event;
import com.laguille.games.monopoly.commons.player.Player;

/**
 * The event bus stores events for one or several clients.
 * The clients have to query the bus to get the latest event.
 *
 */
public interface EventBus {

	/**
	 * Register a player subscription to the event bus.
	 */
	public void registerPlayer(Player player);

	/**
	 * Unregister a player subscription to the event bus.
	 */
	public void unregisterPlayer(Player player);

	/**
	 * Push an event on the bus for a specific player.
	 * @param event the event
	 * @param player the player
	 */
	public void pushEvent(Event event, Player player);
	
	/**
	 * Push an event on the bus for all the players.
	 * @param event the event
	 * @throws IllegalStateException if an event is pushed but no player is registered.
	 */
	public void pushUniversalEvent(Event event);
	
	/**
	 * Pull an event from the bus for a specific player. 
	 * The call will block if no event is on the bus for this specific player until one becomes available.
	 * The returned event is flushed from the bus.
	 * @param player the player
	 * @throws InterruptedException 
	 */
	public Event pullEvent(Player player) throws InterruptedException;
	
	
}
